// Package sysin
// @Link  https://github.com/bufanyun/hotgo
// @Copyright  Copyright (c) 2025 HotGo CLI
// @Author  Ms <133814250@qq.com>
// @License  https://github.com/bufanyun/hotgo/blob/master/LICENSE
// @AutoGenerate Version 2.15.11
package sysin

import (
	"context"
	"hotgo/internal/consts"
	"hotgo/internal/model/entity"
	"hotgo/internal/model/input/form"
	"hotgo/utility/validate"

	"github.com/gogf/gf/v2/errors/gerror"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/os/gtime"
)

// DistributionUpdateFields 修改分销记录字段过滤
type DistributionUpdateFields struct {
	TraceId  string `json:"traceId"  dc:"分销id"`
	OrderUid string `json:"orderUid" dc:"订单 uid"`
	Status   int    `json:"status"   dc:"状态"`
	Type     int    `json:"type"     dc:"类型(1:产品分销,2:会员卡分销)"`
}

// DistributionInsertFields 新增分销记录字段过滤
type DistributionInsertFields struct {
	TraceId  string `json:"traceId"  dc:"分销id"`
	OrderUid string `json:"orderUid" dc:"订单 uid"`
	Status   int    `json:"status"   dc:"状态"`
	Type     int    `json:"type"     dc:"类型(1:产品分销,2:会员卡分销)"`
}

// DistributionEditInp 修改/新增分销记录
type DistributionEditInp struct {
	entity.Distribution
}

func (in *DistributionEditInp) Filter(ctx context.Context) (err error) {
	// 验证分销id
	if err := g.Validator().Rules("required").Data(in.TraceId).Messages("分销id不能为空").Run(ctx); err != nil {
		return err.Current()
	}

	// 验证订单 uid
	if err := g.Validator().Rules("required").Data(in.OrderUid).Messages("订单 uid不能为空").Run(ctx); err != nil {
		return err.Current()
	}

	return
}

type DistributionEditModel struct{}

// DistributionDeleteInp 删除分销记录
type DistributionDeleteInp struct {
	Id interface{} `json:"id" v:"required#id不能为空" dc:"id"`
}

func (in *DistributionDeleteInp) Filter(ctx context.Context) (err error) {
	return
}

type DistributionDeleteModel struct{}

// DistributionViewInp 获取指定分销记录信息
type DistributionViewInp struct {
	Id int64 `json:"id" v:"required#id不能为空" dc:"id"`
}

func (in *DistributionViewInp) Filter(ctx context.Context) (err error) {
	return
}

type DistributionViewModel struct {
	entity.Distribution
}

// DistributionListInp 获取分销记录列表
type DistributionListInp struct {
	form.PageReq
	Id        int64         `json:"id"        dc:"id"`
	TraceId   string        `json:"traceId"   dc:"分销id"`
	OrderUid  string        `json:"orderUid"  dc:"订单 uid"`
	Status    int           `json:"status"    dc:"状态"`
	CreatedAt []*gtime.Time `json:"createdAt" dc:"创建时间"`
}

func (in *DistributionListInp) Filter(ctx context.Context) (err error) {
	return
}

type DistributionListModel struct {
	Id                 int64       `json:"id"                 dc:"id"`
	TraceId            string      `json:"traceId"            dc:"分销id"`
	OrderUid           string      `json:"orderUid"           dc:"订单 uid"`
	Status             int         `json:"status"             dc:"状态"`
	CreatedAt          *gtime.Time `json:"createdAt"          dc:"创建时间"`
	OrderVipProportion int         `json:"orderVipProportion" dc:"会员利润分配比例(%)"`
}

// DistributionExportModel 导出分销记录
type DistributionExportModel struct {
	Id                 int64       `json:"id"                 dc:"id"`
	TraceId            string      `json:"traceId"            dc:"分销id"`
	OrderUid           string      `json:"orderUid"           dc:"订单 uid"`
	Status             int         `json:"status"             dc:"状态"`
	CreatedAt          *gtime.Time `json:"createdAt"          dc:"创建时间"`
	OrderVipProportion int         `json:"orderVipProportion" dc:"会员利润分配比例(%)"`
}

// DistributionStatusInp 更新分销记录状态
type DistributionStatusInp struct {
	Id     int64 `json:"id" v:"required#id不能为空" dc:"id"`
	Status int   `json:"status" dc:"状态"`
}

func (in *DistributionStatusInp) Filter(ctx context.Context) (err error) {
	if in.Id <= 0 {
		err = gerror.New("id不能为空")
		return
	}

	if in.Status <= 0 {
		err = gerror.New("状态不能为空")
		return
	}

	if !validate.InSlice(consts.StatusSlice, in.Status) {
		err = gerror.New("状态不正确")
		return
	}
	return
}

type DistributionStatusModel struct{}
